package com.woniuxy.order.exception;

import com.woniuxy.order.entity.JsonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice("com.woniuxy.order")
@ResponseBody
public class ControllerExceptionAdvice {
    final static Logger LOG = LoggerFactory.getLogger(ControllerExceptionAdvice.class);

    @ExceptionHandler(Exception.class)
    public Object exceptionHandler(Exception e) {
        LOG.error("", e);
        return JsonResponse.serverError().setMsg("调用异常");
    }

    @ExceptionHandler(BindException.class)
    public Object exceptionHandler(BindException e) {
        LOG.error("", e);
        return JsonResponse.serverError().setMsg("参数校验异常");
    }
}
